<?php

namespace App\Admin\Renderables\Ddb;

use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class SameNameRenderTable extends LazyRenderable
{
    public function grid(): Grid
    {
        $modelClass = $this->payload['model_class'];
        $name = $this->payload['name'];
        $zdys = isset($this->payload['zdys']) ? $this->payload['zdys'] : 0;
        $zdps = isset($this->payload['zdps']) ? $this->payload['zdps'] : 0;
        if($zdys > 0){
            $zdys = '提名党员数<br/>（总数：'.$zdys.'）';
        }
        if($zdps > 0){
            $zdps = '提名支部数<br/>（总数：'.$zdps.'）';
        }
        // $csrq = $this->payload['csrq'];
        $builder = $modelClass::query()->where('name', $name);
        return Grid::make($builder, function (Grid $grid) use ($zdys, $zdps) {
            $grid->column('name')->width('100px');
            $grid->column('dwzw');
            $grid->column('sex');
            $grid->column('mz');
            $grid->column('csrq');
            $grid->column('rdsj');
            $grid->column('cjgzsj');
            $grid->column('dps', $zdps)->width('130px');
            $grid->column('dys', $zdys)->width('130px');
//            $grid->column('zdps');
//            $grid->column('zdys');
            // $grid->column('yjdzz')->style('word-break:break-all; white-space:initial;');
            // $grid->column('dzb')->style('word-break:break-all; white-space:initial;');
            $grid->column('dwmc', '提名单位')->style('word-break:break-all; white-space:initial;');
            $grid->paginate(15);
            $grid->disableActions()->disableRowSelector()->disablePagination();
        });
    }
}